package com.tz.marlon.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.tz.marlon.bean.User;

/**
 * 
 * LoginIntercetor<BR>
 * 作者:Marlon  <BR>
 * 时间:2016年5月22日 下午12:10:23  <BR>
 * 电话:18093454447  <BR>
 * 邮箱:18093454447@163.com  <BR>
 * @version 1.0.0  <BR>
 * @link see:  <BR>
 *
 */
public class LoginIntercetor implements HandlerInterceptor{

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		User user = (User) request.getSession().getAttribute("user");
		if(user!=null){
			return true;
		}else{
			//如果没有登录就让他返回到首页
			response.sendRedirect(request.getContextPath()+"/");	
			return true;
		}
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("请求结束执行的方法..........");
		
	}
	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("响应已经被渲染成功后执行的方法..........");
		
	}

}
